<?php
/**
 * Created by PhpStorm
 * User: whh
 * Date: 2022/7/23
 * Time: 11:53
 */

namespace app\backstage\model;


use app\common\model\Common;
use app\common\model\QuickApp;
use think\Db;
use think\Model;

class ManagerUser extends Model
{
    use Common;

    protected $table = 'cms_manager_user';

    public function role()
    {
        return $this->hasOne(ManagerRole::class, 'id', 'role_id');
    }

    public function parent()
    {
        return $this->hasOne(ManagerUser::class, 'id', 'parent_id')->field("id,account");
    }


    public function apps()
    {
        return $this->belongsToMany(QuickApp::class, QuickAppToManagerAccess::class, 'quick_id', 'uid')->field("id,name");
    }


    /**
     * 获取下属用户id
     * @param $uid
     * @return array
     * @Author: whh
     */
    public function sonUsersIds($uid)
    {
        return Db::table($this->table)->where("parent_id", $uid)->column('id');
    }
}